docs: Update the coding style
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 4 Jul 2013 23:09:37 +0000 (00:09 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 9 Jul 2013 08:30:02 +0000 (09:30 +0100)
We should mention that newly written code should not have the private
data pointer in the instance structure, and that private data should be
added using the new GObject macros.

https://bugzilla.gnome.org/show_bug.cgi?id=702996

docs/CODING-STYLE

index ae6e9fbc7c223e93b4049fe2f46f1db6134a5ee2..6ee0a971ad3c4f6d2f51544ba3090238a6ec4f27 100644 (file)
@@ -499,8 +499,9 @@ And callback types:
   typedef void (* GtkCallback) (GtkWidget *widget,
                                 gpointer   user_data);
 
-Instance structures should only contain the parent type and a pointer to a
-private data structure, and they should be annotated as "private":
+Instance structures should only contain the parent type, and optionally a
+pointer to a private data structure, and they should be annotated as
+"private" using the gtk-doc trigraph:
 
   struct _GtkFoo
   {
@@ -510,21 +511,26 @@ private data structure, and they should be annotated as "private":
     GtkFooPrivate *priv;
   };
 
+The private data pointer is optional and should be omitted in newly
+written classes.
+
+Always use the G_DEFINE_TYPE(), G_DEFINE_TYPE_WITH_PRIVATE(), and
+G_DEFINE_TYPE_WITH_CODE() macros, or their abstract variants
+G_DEFINE_ABSTRACT_TYPE(), G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(), and
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE(); also, use the similar macros for
+defining interfaces and boxed types.
+
 All the properties should be stored inside the private data structure, which
 is defined inside the source file - or, if needed, inside a private header
 file; the private header filename must end with "private.h" and must not be
 installed.
 
-The private data structure should only be accessed internally using the
-pointer inside the instance structure, and never using the
+The private data structure should only be accessed internally either using the
+pointer inside the instance structure, if one is available, or the generated
+instance private data getter function for your type. You should never use the
 G_TYPE_INSTANCE_GET_PRIVATE() macro or the g_type_instance_get_private()
 function.
 
-Always use the G_DEFINE_TYPE(), G_DEFINE_TYPE_WITH_CODE() macros, or
-their abstract variants G_DEFINE_ABSTRACT_TYPE() and
-G_DEFINE_ABSTRACT_TYPE_WITH_CODE(), and the similar macros for defining
-interfaces.
-
 Interface types should always have the dummy typedef for cast purposes:
 
         typedef struct _GtkFoo              GtkFoo;